Skip to content

Conversation

@heath-hunnicutt-ruach-tov
Copy link

@heath-hunnicutt-ruach-tov heath-hunnicutt-ruach-tov commented Jan 30, 2026

Summary

  • Parse Google, NumPy, and Sphinx-style docstrings to automatically populate parameter descriptions in tool/prompt/resource JSON schemas
  • Previously, parameter descriptions required explicit Field(description=...) annotations; now they can come from standard docstrings
  • Field(description=...) annotations take precedence when both are present, ensuring full backward compatibility

Closes #226

Changes

  • New: src/mcp/server/mcpserver/utilities/docstring_utils.py — docstring parsing utility using griffe with auto-detection of Google/NumPy/Sphinx formats
  • Modified: func_metadata() accepts optional param_descriptions dict, injected as fallback when no Field(description=...) exists
  • Modified: Tool.from_function(), Prompt.from_function(), ResourceTemplate.from_function() — parse docstrings and pass results through
  • Modified: pyproject.toml — added griffe>=1.0 as runtime dependency
  • New: 8 unit tests for parsing utility + 7 integration tests covering all formats, precedence rules, and edge cases

Test plan

  • All 8 test_docstring_utils.py tests pass
  • All 8 test_parameter_descriptions.py tests pass (1 existing + 7 new)
  • All 243 existing mcpserver tests pass with zero regressions
  • CI passes on all supported Python versions (3.10–3.14)

🤖 Generated with Claude Code

Parse Google, NumPy, and Sphinx-style docstrings to automatically
populate parameter descriptions in tool/prompt/resource JSON schemas.
Previously, parameter descriptions required explicit Field(description=...)
annotations. Now they can come from standard docstrings, with Field()
annotations taking precedence when both are present.

Closes modelcontextprotocol#226

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improving how function docstring gets converted to tool's jsonschema for FastMCP

1 participant